window.addEventListener("load", () => {
    let user_n = document.getElementById("user_n")
    console.log(user_n.value)
    user_n.addEventListener("input",(e)=>{
        console.log("输入框输入了",e.target.value)
    })

    let sexMale = document.getElementById("male")
    console.log(sexMale.checked)
    sexMale.checked = true
    sexMale.addEventListener("change",(e)=>{
        console.log("复选框有变动")
        console.log(sexMale.checked)
    })
    let female =document.getElementById("female")
    console.log(female.checked)
    female.addEventListener("change",(e)=>{
        console.log("复选框",e.target.checked)
        console.log(female.checked)
    })
    let fruit = document.querySelector("#fruit")
    console.log(fruit.value)
    fruit.addEventListener("change",(e)=>{
        console.log("选择了",e.target.value)
    })
            const base = 'http://127.0.0.1:8080/test';

        function log(data) {
            document.getElementById('result').textContent = JSON.stringify(data, null, 2);
        }

        async function doGet() {
            const p = new URLSearchParams({user_n: document.getElementById('user_n').value});
            const res = await fetch(`${base}?${p}`);
            log(await res.json());
        }

        async function doPost() {
            const p = new URLSearchParams({ post_user: document.getElementById('post_user').value });
            const res = await fetch(base, {method:'POST', body:p});
            log(await res.json());
        }
    // const postForm = document.getElementById('postForm'); // 记得给 form 加 id="postForm"
    // postForm.addEventListener('submit', (e) => {
    //     // e.preventDefault(); // 阻止跳转
    //     doPost();
    // });
});
